# Portfolio System Makefile

.PHONY: help build up down restart logs clean backup restore

# 默认目标
help:
	@echo "Portfolio System Docker 管理命令:"
	@echo ""
	@echo "  build     - 构建 Docker 镜像"
	@echo "  up        - 启动所有服务"
	@echo "  down      - 停止所有服务"
	@echo "  restart   - 重启所有服务"
	@echo "  logs      - 查看服务日志"
	@echo "  clean     - 清理 Docker 资源"
	@echo "  backup    - 备份数据库"
	@echo "  restore   - 恢复数据库"
	@echo "  status    - 查看服务状态"
	@echo ""

# 构建镜像
build:
	@echo "🔨 构建 Docker 镜像..."
	docker-compose build --no-cache

# 启动服务
up:
	@echo "🚀 启动服务..."
	docker-compose up -d
	@echo "✅ 服务已启动"
	@echo "📱 访问地址: http://localhost:9080"

# 停止服务
down:
	@echo "🛑 停止服务..."
	docker-compose down

# 重启服务
restart:
	@echo "🔄 重启服务..."
	docker-compose restart

# 查看日志
logs:
	docker-compose logs -f

# 查看服务状态
status:
	docker-compose ps

# 清理资源
clean:
	@echo "🧹 清理 Docker 资源..."
	docker-compose down -v
	docker system prune -f

# 备份数据库
backup:
	@echo "💾 备份数据库..."
	docker-compose exec postgres pg_dump -U portfolio_user portfolio_db > backup_$(shell date +%Y%m%d_%H%M%S).sql
	@echo "✅ 备份完成"

# 恢复数据库
restore:
	@echo "📥 恢复数据库..."
	@read -p "请输入备份文件路径: " backup_file; \
	docker-compose exec -T postgres psql -U portfolio_user portfolio_db < $$backup_file
	@echo "✅ 恢复完成"

# 完整部署（构建+启动）
deploy: build up

# 开发环境启动
dev:
	@echo "🔧 启动开发环境..."
	docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d

# 生产环境启动（包含 Nginx）
prod:
	@echo "🌐 启动生产环境..."
	docker-compose --profile nginx up -d